package com.onesports.intelligent.k12.polarlight.controller.wx.apply;

import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.wx.CoachApplyDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.wx.CoachApplyVO;
import com.onesports.intelligent.k12.polarlight.security.SecurityUtils;
import com.onesports.intelligent.k12.polarlight.service.wx.CoachApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author wangcx
 */
@Api(value = "小程序端", tags = "小程序端-教练管理")
@RestController
@RequestMapping(ApiPathConstants.WX_COACH)
@RequiredArgsConstructor
@PreAuthorize("hasAuthority('MINI_APP')")
public class WxCoachController {

    private final CoachApplyService service;

    @PostMapping("/apply")
    @ApiOperation(value = "教练申请")
    public ResponseEntity apply(@Valid @RequestBody CoachApplyDTO dto) {

        dto.setWxUserId(SecurityUtils.getAccountId());
        dto.setApplyPhone(SecurityUtils.getPhone());
        this.service.apply(dto);
        return ResultUtil.success("申请成功");
    }


    @GetMapping("/get-apply")
    @ApiOperation(value = "我的申请")
    public ResponseEntity<List<CoachApplyVO>> getApply(){
        return ResultUtil.success(this.service.getApply(SecurityUtils.getAccountId()));
    }

}
